<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:t="http://myfaces.apache.org/tomahawk">
<ui:composition template="Admin-template.xhtml">
	<ui:param name="title" value="QUẢN LÝ SẢN PHẨM" />
	<ui:define name="body">
		<h:form id="manageProduct_criteria">
			<h:panelGrid columns="2">
				<h:outputText value="ID"/>
				<h:inputText value="#{manageProductBean.id}"/>
				
				<h:outputText value="Nhóm"/>
				<h:selectOneListbox value="#{manageProductBean.cateCode}" size="1" onchange="$('.btnLoadSubcat').click()">
					<f:selectItem itemLabel="" itemValue=""/>
					<c:forEach items="#{mstBean.allCategories}" var="aCat">
						<f:selectItem itemLabel="#{aCat.name}" itemValue="#{aCat.code}" />
					</c:forEach>
					<f:ajax event="select" execute="@form" render="@form" listener="#{managerProduct.loadSubCats}"/>
				</h:selectOneListbox>
				
				<h:outputText value="Nhóm con"/>
				<h:selectOneListbox value="#{manageProductBean.subcatCode}" size="1">
					<f:selectItem itemLabel="" itemValue=""/>
					<c:forEach items="#{manageProductBean.subCats}" var="aSubCat">
						<f:selectItem itemLabel="#{aSubCat.name}" itemValue="#{aSubCat.code}" />
					</c:forEach>
				</h:selectOneListbox>
				
				<h:outputText value="Mã"/>
				<h:inputText value="#{manageProductBean.name}"/>
				
				<h:outputText value="Đặc biệt"/>
				<h:selectOneListbox value="#{manageProductBean.special}" size="1">
					<f:selectItem itemLabel="Cả hai" itemValue="both"/>
					<f:selectItem itemLabel="Bình thường" itemValue="normal"/>
					<f:selectItem itemLabel="Đặc biệt" itemValue="special"/>
				</h:selectOneListbox>
				
				<h:outputText value="Khuyến mãi"/>
				<h:selectOneListbox value="#{manageProductBean.sale}" size="1">
					<f:selectItem itemLabel="Cả hai" itemValue="both"/>
					<f:selectItem itemLabel="Không khuyến mãi" itemValue="nosale"/>
					<f:selectItem itemLabel="Khuyến mãi" itemValue="sale"/>
				</h:selectOneListbox>
				
				<h:commandButton value="Tìm kiếm" action="#{manageProductBean.search}"/>
				<h:commandButton value="Xóa" action="#{manageProductBean.clear}"/>
			</h:panelGrid>
			<h:commandButton styleClass="btnLoadSubcat" style="display:none" action="#{manageProductBean.loadSubCats}"/>
		</h:form>
		
		<h:form id="manageProduct_results">
			<h3>Kết quả tìm kiếm</h3>
			<br></br>
			#{manageProductBean.nSearchResults} kết quả
			<br></br>
			<h:commandButton value="Thêm sản phẩm" action="#{createProductBean.init()}"/>
			<br></br>
			<table border="1">
				<tr>
					<td></td>
					<td>ID</td>
					<td>Mã</td>
					<td>Nhóm</td>
					<td>Nhóm con</td>
					<td>Mô tả</td>
					<td>Giá</td>
					<td>Giá khuyến mãi</td>
					<td>Số lượng</td>
					<td>Hình ảnh</td>
					<td>Đặc biệt</td>
					<td>Khuyến mãi</td>
				</tr>
				<c:forEach var="aProduct" items="#{manageProductBean.searchResults}">
					<tr>
						<td>
							<t:div>
								<h:commandButton value="Xóa" action="#{manageProductBean.delete}">
									<f:setPropertyActionListener target="#{manageProductBean.deletedProductId}" value="#{aProduct.id}"/>
								</h:commandButton>
							</t:div>
						</td>
						<td>#{aProduct.id}</td>
						<td>
							<h:commandLink value="#{aProduct.name}" action="#{editProductBean.init}">
								<f:setPropertyActionListener target="#{editProductBean.edittedProductId}" value="#{aProduct.id}" />
							</h:commandLink>
						</td>
						<td>#{aProduct.category.name}</td>
						<td>#{aProduct.subCat.name}</td>
						<td>#{aProduct.detail}</td>
						<td>#{aProduct.price}</td>
						<td>#{aProduct.salePrice}</td>
						<td>#{aProduct.quantity}</td>
						<td><h:graphicImage url="#{aProduct.image}" width="150px"/></td>
						<td>
							<h:outputText value="Đặc biệt" rendered="#{aProduct.special}"/>
						</td>
						<td>
							<h:outputText value="Khuyến mãi" rendered="#{aProduct.sale}"/>
						</td>
					</tr>
				</c:forEach>
			</table>
		</h:form>
	</ui:define>
</ui:composition>
</html>